package com.rfid.assistant.activity.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.rfid.assistant.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import com.rfid.assistant.base.BaseAdapter;
import com.rfid.webp2plib.User;

public class DeviceAdapter extends BaseAdapter<DeviceAdapter.Holder, User> {


    public DeviceAdapter(List<User> data) {
        super(data);
    }

    @Override
    protected void bindView(Holder holder, int position) {
        User user = mData.get(position);
        holder.name.setText(user.getData().getName() + "-" + user.getData().getExtraInfo());
        holder.pkg.setText(user.getData().getPkg());
        holder.ver.setText(user.getData().getVer() + "("+ user.getData().getCode() + ")");
        holder.ip.setText(user.getData().getIp());
        holder.deviceId.setText(user.getId());
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_device,parent,false));
    }

    class Holder extends RecyclerView.ViewHolder {

        @BindView(R.id.name)
        TextView name;
        @BindView(R.id.pkg)
        TextView pkg;
        @BindView(R.id.ver)
        TextView ver;
        @BindView(R.id.ip)
        TextView ip;
        @BindView(R.id.deviceId)
        TextView deviceId;
        public Holder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
